package com.book.xsp.bookparent.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.book.xsp.bookparent.entity.Course;
import com.book.xsp.bookparent.entity.Student;
import com.book.xsp.bookparent.entity.StudentScore;
import com.book.xsp.bookparent.entity.vo.StudentScoreVo;
import com.book.xsp.bookparent.mapper.StudentScoreMapper;
import com.book.xsp.bookparent.service.ICourseService;
import com.book.xsp.bookparent.service.IStudentScoreService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author snake_skin
 * @since 2023-11-29
 */
@Service
public class StudentScoreServiceImpl extends ServiceImpl<StudentScoreMapper, StudentScore> implements IStudentScoreService {

    @Resource
    ICourseService iCourseService;

    @Override
    public List<StudentScoreVo> getAllStudentService() {
        List<StudentScoreVo> studentScoreVoList= baseMapper.getAllStudentScore();
        return studentScoreVoList;
    }

    @Override
    public boolean addStudentScore(StudentScoreVo studentScoreVo) {
        StudentScore studentScore = new StudentScore();
        Long courseId = iCourseService.getCourseIdByName(studentScoreVo.getCourseName());
        studentScore.setCourseId(Integer.parseInt(courseId.toString()));
        studentScore.setStudentNo(studentScoreVo.getStudentNo());
        studentScore.setScore(studentScoreVo.getScore());
        int insert = baseMapper.insert(studentScore);
        return insert > 0;
    }
}
